/**
 * ----------------------------------------------------------------------------
 * Copyright Jens Konopka
 * 
 * Alle Rechte vorbehalten.
 * Licence: Apache 2.0
 * ----------------------------------------------------------------------------
 *
 * created on 04.03.2012 by jkonopka
 */
package de.sql.toolkit.reader;

import java.util.List;

import de.sql.toolkit.model.Column;
import de.sql.toolkit.model.Table;
import de.sql.toolkit.provider.ColumnProvider;
import de.sql.toolkit.provider.TableProvider;

/**
 * @author jkonopka
 * 
 */
public class CreateTableScriptReader extends AbstractReader<List<Table>> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3962912250320126897L;
	private String schema;

	/**
	 * @param schema
	 */
	public CreateTableScriptReader(String schema) {
		super();
		this.schema = schema;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.sql.toolkit.reader.IReader#read()
	 */
	@Override
	public List<Table> read() throws Exception {
		final TableProvider tblProvider = new TableProvider();
		final List<Table> tables = tblProvider.select(getSchema());
		for (final Table table : tables) {
			final ColumnProvider columnProvider = new ColumnProvider();
			final List<Column> columns = columnProvider.select(getSchema(), table.getName());
			table.setColumns(columns);
		}
		return tables;
	}

	/**
	 * @return the schema
	 */
	public String getSchema() {
		return schema;
	}

	/**
	 * @param schema the schema to set
	 */
	public void setSchema(String schema) {
		this.schema = schema;
	}

}
